# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dwd.tab.dwd_dependent_hi.dwd_yl_tmsnew_tms_shipment_base_hf_23 import dwd_yl_tmsnew_tms_shipment_base_hf_23

jms_dm__dm_shipno_change_detail_new = SparkSubmitOperator(
    task_id='jms_dm__dm_shipno_change_detail_new',
    pool_slots=7,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dm__dm_shipno_change_detail_new_{{ execution_date | cst_ds }}',  # yarn 任务名称
    execution_timeout=timedelta(hours=2),
    email=['jarl.huang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    driver_cores=4,
    driver_memory='8G',
    executor_cores=2,
    executor_memory='16G',
    num_executors=16,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors'             : 30,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead'                    : '2G',  # 堆外内存
          'spark.sql.shuffle.partitions'                     : 2400,
          'spark.default.paralleism'                         : 2400,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 180,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 20 个分区
              },
    jars='hdfs:///scheduler/jms/spark/zjhuang/original-common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.ShipnoWeightChangeDataNew',  # spark 主类
    # spark jar 包
    application='hdfs:///scheduler/jms/spark/zjhuang/dm_shipno_change_detail_new/original-jobs-1.0-SNAPSHOT.jar',
    application_args=['{{ execution_date | cst_ds }}'],  # 参数dt 2020-10-26
)

# 设置依赖
jms_dm__dm_shipno_change_detail_new << [
    dwd_yl_tmsnew_tms_shipment_base_hf_23
]
